#include "SearchResTweetData.h"
#include "JSONString.h"

SearchResTweetData::SearchResTweetData(void)
{
	_result = 0;
}

SearchResTweetData::~SearchResTweetData(void)
{
}

void SearchResTweetData::setData(std::istream &is)
{
	TwitterData::setData(is);
	_result = dynamic_cast<JSONArray *>(json.getData("results"));
}

std::string SearchResTweetData::getData() 
{
	return "";
};

unsigned long SearchResTweetData::getResSize()
{
	if(_result != 0){
		return _result->getSize();
	}

	return 0;
}

std::string   SearchResTweetData::getResTweetInfo(unsigned long index, std::string tag)
{
	if(_result == 0 || _result->getSize() <= index){
		return "";
	}

	JSONObject * twitter = dynamic_cast<JSONObject *>(_result->getData(index));
	JSONString * pString = 0;
	pString = dynamic_cast<JSONString *>(twitter->getData(tag));
	return pString->getData();
}

std::string   SearchResTweetData::getResTweetID(unsigned long index)
{
	return getResTweetInfo(index, "id_str");
}

std::string   SearchResTweetData::getResTweetCreatedTime(unsigned long index)
{
	return getResTweetInfo(index, "created_at");
}

std::string   SearchResTweetData::getResTweetFromUserID(unsigned long index)
{
	return getResTweetInfo(index, "from_user_id_str");
}

std::string   SearchResTweetData::getResTweetText(unsigned long index)
{
	return getResTweetInfo(index, "text");
}